from django.utils.deprecation import MiddlewareMixin
from app002.models import UserLog
from user_agents import parse


class UserLogMiddleWare(MiddlewareMixin):
    def process_request(self, request):
        path = request.get_full_path()
        method = request.method
        ip = request.META.get('REMOTE_ADDR')
        user_agent = request.META.get('HTTP_USER_AGENT')
        ua = parse(user_agent)
        browser = ua.browser.family
        version = ua.browser.version_string
        UserLog.objects.create(path=path, method=method, ip=ip, user_agent=user_agent, browser=browser, version=version)


class LimitVisitMiddleWare(MiddlewareMixin):
    user_info_list = []

    def process_request(self, request):
        ...
